<?php
/**
 * 完善订单拦截器
 * Enter description here ...
 * @author nijn
 *
 */
class PerfectOrderBehavior extends CActiveRecordBehavior{

	public function beforeSave($event) {
		$owner = $this->owner;
		$cascade = $owner->cascade;
		$relations = $owner->relations();
		$break = true;
		if ($owner->status != 'ST_DEALER_CONFIRMED') return false;
		foreach ($cascade as $one) {
			if (isset($relations[$one])) {
				if ($relations[$one][0] == CActiveRecord::HAS_MANY) {
					foreach ($owner->$one as $hasMany) {
						$break = $hasMany->save();
					}
				} else if ($relations[$one][0] == CActiveRecord::HAS_ONE) {
					$hasOne = $owner->$one;
					if (is_object($hasOne))
						$break = $hasOne->save();
					else 
						$break = false;
				}
					
			}
			if (!$break) {
				Yii::app()->user->setFlash(FLASH::RESULT_FAILED,  '请先完善订单信息！');
				$event->isValid = false;
			}
		}
	}
}

?>